package com.myres.struts2.action;

import java.util.Iterator;
import java.util.Set;

import com.myres.model.Category;
import com.myres.model.Series;
import com.myres.service.CategoryService;
import com.opensymphony.xwork2.ActionSupport;

public class AddSerialAction extends ActionSupport {

	
   private String seriesXML ;
   private CategoryService categoryService;
   private int categoryId;
	

	public CategoryService getCategoryService() {
	return categoryService;
}

public void setCategoryService(CategoryService categoryService) {
	this.categoryService = categoryService;
}

public int getCategoryId() {
	return categoryId;
}

public void setCategoryId(int categoryId) {
	this.categoryId = categoryId;
}

	public String getSeriesXML() {
		return seriesXML;
	}

	public void setSeriesXML(String seriesXML) {
		this.seriesXML = seriesXML;
	}
	/**
	 * @return
	 */
	public String execute() {
		Category cate = categoryService.get(categoryId);
		Set<Series> series= cate.getSerieses();
		StringBuilder sb=new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
		sb.append("<series>"); 
		Iterator<Series> iter=series.iterator();
		
		while(iter.hasNext()){
			Series s= iter.next();
			sb.append("<serial>");
			sb.append("<id>");
			sb.append(s.getId());
			sb.append("</id>");
			sb.append("<name>");
			sb.append(s.getName());
			sb.append("</name>");
			sb.append("</serial>");
		}
		sb.append("</series>");
		this.seriesXML = sb.toString();
		System.out.print("xml="+this.seriesXML);
		return SUCCESS;
	}
}